package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/22 14:28
 * @version  V1.0
 * @description:
 *
 */
//定义一个结构体Account
type Account struct {
	AccountNo string
	Pwd       string
	Balance   float64
}

//方法
//1. 存款
func (account *Account) Deposite(money float64, pwd string) {

	//看下输入的密码是否正确
	if pwd != account.Pwd {
		fmt.Println("你输入的密码不正确")
		return
	}

	//看看存款金额是否正确
	if money <= 0 {
		fmt.Println("你输入的金额不正确")
		return
	}

	account.Balance += money
	fmt.Println("存款成功~~")

}

//取款
func (account *Account) WithDraw(money float64, pwd string) {

	//看下输入的密码是否正确
	if pwd != account.Pwd {
		fmt.Println("你输入的密码不正确")
		return
	}

	//看看取款金额是否正确
	if money <= 0 || money > account.Balance {
		fmt.Println("你输入的金额不正确")
		return
	}

	account.Balance -= money
	fmt.Println("取款成功~~")

}

//查询余额
func (account *Account) Query(pwd string) {

	//看下输入的密码是否正确
	if pwd != account.Pwd {
		fmt.Println("你输入的密码不正确")
		return
	}

	fmt.Printf("你的账号为=%v 余额=%v \n", account.AccountNo, account.Balance)

}

func main() {

	//测试一把
	account := Account{
		AccountNo: "gs1111111",
		Pwd:       "666666",
		Balance:   100.0,
	}

	//这里可以做的更加灵活，就是让用户通过控制台来输入命令...
	//菜单....
	//account.Query("666666")
	//account.Deposite(200.0, "666666")
	//account.Query("666666")
	//account.WithDraw(150.0, "666666")
	//account.Query("666666")

	var op string
	var saveBalance float64
	var getBalance float64
	var password string

	for {
		fmt.Println("1  存款")
		fmt.Println("2  取款")
		fmt.Println("3  查询余额")
		fmt.Println("请输入您想要的操作:")
		fmt.Scanln(&op)
		switch op {
		case "1":
			fmt.Println("请输入存款金额:")
			fmt.Scanln(&saveBalance)
			fmt.Println("请输入密码:")
			fmt.Scanln(&password)
			account.Deposite(saveBalance, password)
		case "2":
			fmt.Println("请输入取款金额:")
			fmt.Scanln(&getBalance)
			fmt.Println("请输入密码:")
			fmt.Scanln(&password)
			account.WithDraw(getBalance, password)
		case "3":
			fmt.Println("请输入密码:")
			fmt.Scanln(&password)
			account.Query(password)
		default:
			fmt.Println("输入有误,请重新输入:")
		}
	}

}
